import os
import sys

sys.path.append(os.path.dirname(__file__))
import requests

OLLAMA_URL = "http://localhost:11434/api/chat"
MODEL_NAME = "qwen3:8b"


class LLMClient:
    def __init__(self, base_url=OLLAMA_URL, model=MODEL_NAME):
        self.base_url = base_url
        self.model = model

    def generate_sql(self, prompt: str) -> str:
        payload = {
            "model": self.model,
            "messages": [
                {"role": "user", "content": prompt}
            ],
            "stream": False
        }
        resp = requests.post(self.base_url, json=payload, timeout=60)
        resp.raise_for_status()
        result = resp.json()
        return result.get("message", {}).get("content", "")
